﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace OldFramework
{

    public class Human : AnimalBase, IWalkableAnimal, ITalkableAnimal, INamedAnimal
    {
        public Human()
        {
            _Name = string.Concat(Guid.NewGuid().ToString().Substring(0, 4));
            Age = Guid.NewGuid().ToByteArray().FirstOrDefault();
        }

        public Human(string name)
        {
            _Name = name;
        }

        string _Name = "";
        public override string CategoryName => "灵长类";
        public override string EthnicGroupName => "人";

        public string Name => _Name;

        public override void Move()
        {
            if (Age < 1)
            {
                Console.WriteLine($"{Name} can crawl!");
            }
            else
            {
                Console.WriteLine($"{Name} walked !");
            }
        }

        void ITalkableAnimal.Talk()
        {
            if (Age < 3)
            {
                Console.WriteLine($"{Name}:cry !");
            }
            else
            {
                Console.WriteLine($"{Name}:Hello,there!");
            }

        }

        void ITalkableAnimal.Talk(AnimalBase animal)
        {
            if (Age < 3)
            {
                Console.WriteLine($"{Name}:cry !");
            }
            else if (animal is INamedAnimal)
            {
                Console.WriteLine($"{Name}:Hello,{(animal as INamedAnimal).Name}!");
            }
            else
            {
                Console.WriteLine($"{Name}:Hello,{animal.EthnicGroupName}!");
            }
        }

        void IWalkableAnimal.Walk()
        {
            if (Age < 1)
            {
                Console.WriteLine($"{Name} can walk,but crawl!");
            }
            else
            {
                Console.WriteLine($"{Name} walked !");
            }
        }


        public override string ToString()
        {
            Console.WriteLine(Assembly.GetEntryAssembly().FullName);
            return $"\"祝我生日快乐!\",这是{CategoryName}{EthnicGroupName}的{Name}在庆祝它{Age}的生日";
        }
    }
}
